#include "process.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define GREEN  "\033[1;32m"
#define YELLOW "\033[1;33m"
#define RED    "\033[1;31m"
#define BLUE   "\033[1;34m"
#define RESET  "\033[0m"
#define N 101
#define c '='

void FlushProcess(double total, double current) {
    char buffer[N];
    memset(buffer, 0, sizeof(buffer));
    const char* s = "|\\-/";
    int len = strlen(s);
    static int k = 0;
    int cur = (int)(current * 100 / total);
    for(int i = 0 ;i < cur; i++) {
        buffer[i] = c;
    }
    double rate = current * 100 / total;
    // printf("[%-100s][%.1lf%%][%c]\r", buffer, rate, s[k % len]);
    printf(GREEN "[%-100s]" RESET YELLOW "[%.1lf%%]" RESET BLUE "[%c]" RESET "\r",
       buffer, rate, s[k % len]);

    k++;
    fflush(stdout);
}